using System;

using Pegasus.Diagnostics;
using Pegasus.Workflow.Service;

namespace Pegasus.UnitTests.Workflow.Service.Workflows
{
	/// <summary>
	/// The starting state that catches the first event in the event workflow test.
	/// </summary>
	public class StateCatchFirstEvent : WorkflowState
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="T:StateCatchFirstEvent"/> class.
		/// </summary>
		public StateCatchFirstEvent() :
			base( "StateCatchFirstEvent" )
		{
		}

		/// <summary>
		/// Called when intialize complete of the workflow is completed.
		/// </summary>
		protected override void OnIntializeComplete()
		{
			base.OnIntializeComplete();

			// Bind to the data exchange event
			TestDataExchangeService dataExchangeService = Workflow.GetService<TestDataExchangeService>();
			dataExchangeService.FirstEvent += new EventHandler<TestingEventArgs>( DataExchangeService_FirstEvent );
		}

		/// <summary>
		/// Handles the FirstEvent event of the DataExchangeService control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="args">The <see cref="T:Pegasus.UnitTests.Workflow.Service2.Workflows.TestingEventArgs"/> instance containing the event data.</param>
		private void DataExchangeService_FirstEvent( object sender, TestingEventArgs args )
		{
			Workflow.SetState( "StateCatchSecondEvent" );
		}
	}
}
